﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UWBUpdateMove : MonoBehaviour
{
        /// <summary>
        /// 从这里获取源数据
        /// </summary>
        /// 
        /// <summary>
        /// 模拟场地的ID
        /// </summary>
        public int areaId { get; set; }
        /// <summary>
        /// 锚点显示对象
        /// </summary>
        public Anchor[] anchors;
        /// <summary>
        /// 目标显示对象
        /// </summary>
        public TagLocal[] tags;
        /// <summary>
        /// 结果显示对象
        /// </summary>
        public Result[] results;
        /// <summary>
        /// 当前展示的帧数
        /// </summary>
        public int seq = 0;

        void Awake()
        {
                anchors = this.GetComponentsInChildren<Anchor>();
                tags = this.GetComponentsInChildren<TagLocal>();
                results = this.GetComponentsInChildren<Result>();
                if (anchors.Length < 3)
                {
                        Debug.LogError("锚点数量至少3个！");
                }

                if (tags.Length < 1)
                {
                        Debug.LogError("目标点数量至少1个！");
                }

                for (int i = 0; i < 3; i++)
                {
                        if (anchors[i] != null)
                        {
                                anchors[i].area = this.areaId;
                                anchors[i].id = i;
                                Debug.Log("锚点：" + anchors[i].name);
                        }
                }

                if (tags[0] != null)
                {
                        tags[0].id = 0;
                        Debug.Log("目标点：" + tags[0].name);
                }

                if (results[0] != null)
                {
                        results[0].id = 0;
                        Debug.Log("解：" + results[0].name);
                }
        }

        void Start()
        {
        }


        void Update()
        {
        /*
                if (seq!= tcpClient.dataSeq)
                {
                        seq = tcpClient.dataSeq;

                        float r1, r2, r3;
                        Vec3dInfo tag, anc1, anc2, anc3;

                        tag = new Vec3dInfo();
                        tag.x = tcpClient.tagX;
                        tag.y = tcpClient.tagY;
                        tag.z = tcpClient.tagZ;
                        anc1 = new Vec3dInfo();
                        anc1.x = tcpClient.anchor1X;
                        anc1.y = tcpClient.anchor1Y;
                        anc1.z = tcpClient.anchor1Z;
                        anc2 = new Vec3dInfo();
                        anc2.x = tcpClient.anchor2X;
                        anc2.y = tcpClient.anchor2Y;
                        anc2.z = tcpClient.anchor2Z;
                        anc3 = new Vec3dInfo();
                        anc3.x = tcpClient.anchor3X;
                        anc3.y = tcpClient.anchor3Y;
                        anc3.z = tcpClient.anchor3Z;

                        r1 = tcpClient.r1;
                        r2 = tcpClient.r2;
                        r3 = tcpClient.r3;

                        //设置目标点坐标
                        tags[0].SetTag(tag);
                        //设置锚点坐标
                        anchors[0].SetAnchor(anc1, r1);
                        anchors[1].SetAnchor(anc2, r2);
                        anchors[2].SetAnchor(anc3, r3);
                        
                }
        */
        }
}
